package com.eenie.common.base

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment

abstract class BaseFragment : Fragment() {

    protected lateinit var mContext: Context

    @LayoutRes
    abstract fun initContentView(): Int

    /**
     * 在监听器之前把数据准备好
     */
    abstract fun initData(savedInstanceState: Bundle?)

    /**
     * 初始化控件
     * @param rootView
     */
    abstract fun initUI(rootView: View)


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initUI(view)
    }


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        mContext = requireContext()
        initData(savedInstanceState)
        return inflater.inflate(initContentView(), null)
    }


}